import { Redirect } from 'umi';
import { useLocation } from 'react-router';
import _lodash from 'lodash';
const Wrappers = (props: any) => {
  const location = useLocation();
  const token = window.sessionStorage.getItem('APP_TOKEN');

  const currentPathname =
    location.pathname.indexOf('/sztbuild') === -1
      ? `/sztbuild${location.pathname}`
      : location.pathname;
  const menus = window.sessionStorage.getItem('rolesMenu') || '[]';
  const menusArr = JSON.parse(menus);
  console.log(currentPathname);
  // 判断是否登录
  if (token) {
    //   判断是否有权限
    const hasRoute = _lodash.find(menusArr, { path: currentPathname });
    if (!hasRoute) {
      <Redirect to={`/common/app/login`}></Redirect>;
    }
    return <div>{props.children}</div>;
  } else {
    return <Redirect to={`/common/app/login`}></Redirect>;
  }
};

export default Wrappers;
